package com.qf.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
import com.qf.feign.OrderFeignApi;
import com.qf.pojo.R;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")

@RefreshScope //当配置发生变化后，该注解标注的对象销毁重建
public class UserController4 {

    @Autowired
    private OrderFeignApi orderFeignApi;

    @Value("${desc}")
    private String desc;

    @GetMapping("/{id}")

    public R findOrders(@PathVariable("id") Integer id) throws InterruptedException {
        System.out.println("--------------" + desc);
        R r = orderFeignApi.findByUid(id);
        return r;
    }


    //这个资源是非核心资源
    @GetMapping("/test1")
    public R test1() throws InterruptedException {
        System.out.println("test1--------------" + desc);

        return R.success().putMsg("test1 success...");
    }


    @Autowired
    private UserService userService;

    /*
        非核心业务，当核心业务访问量过大时，对非核心业务进行流控
     */
    @GetMapping("/test2")
    public R test2(){
        userService.queryOrder();

        return R.success().putMsg("test2 success...");
    }

    /*
        核心业务
     */
    @GetMapping("/test3")
    public R test3(){
        userService.queryOrder();

        return R.success().putMsg("test3 success...");
    }
}
